<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="userForm" enctype="multipart/form-data">
                <br/>
                <h3 class="title">Pesquisando Imóvel</h3>

                <p:growl id="messages" showDetail="true" autoUpdate="true"  /> 
                <p:panel id="ownerPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <h4 class="title">Filtros</h4>

                    <!--                                <p:outputLabel id="personOutputLabel" value="Pessoa:" 
                                                                   for="personRadioButton"
                                                                   styleClass="grid_3" style="top: 6px" />
                                                    <div class="grid_8">
                                                        <p:selectOneRadio id="personRadioButton" 
                                                                          value="  {managerSearchRealty.owner.typeDocument}" >
                                                            <f:selectItems value="{managerSearchRealty.typeDocumentList()}" />
                                                            <p:ajax event="change" update=":userForm:ownerPanel" />
                                                        </p:selectOneRadio>
                                                    </div>
                                                    <div class="clear-both" />
                                                    
                                                    <p:outputLabel value={managerSearchRealty.owner.typeDocument.type eq 'CPF' ? 'CPF:' : 'CNPJ:'}" 
                                                                   styleClass="grid_3" for="cpfInputMask" />
                                                    <p:inputMask id="cpfInputMask" styleClass="grid_4" 
                                                                 mask="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                         ? '999.999.999-99' : '99.999.999/9999-99'}"
                                                                 value="{managerSearchRealty.owner.typeDocument.type eq 'CPF' 
                                                                          ? managerSearchRealty.owner.cpf : managerSearchRealty.owner.cnpj}" />
                                                    <div class="clear-both" />-->

                    <!--                                <p:outputLabel value="Proprietário:" styleClass="grid_3" for="ownerAutoComplete" />
                                                    <p:autoComplete id="ownerAutoComplete" styleClass="grid_20" dropdown="true" converter="peopleconverter"
                                                                    var="item" itemLabel="{item.name} {item.cpf}" 
                                                                    itemValue="{item}" value="{managerSearchRealty.owner}" 
                                                                    scrollHeight="200" forceSelection="true"
                                                                    completeMethod="{managerSearchRealty.autocompletePeople}" />-->



                    <p:outputLabel value="Pessoa: "  styleClass="grid_3"/>
                    <p:selectOneRadio id="typePerson" style="margin-top:-8px;" styleClass="grid_8"
                                      value="#{managerSearchRealty.owner.tipoDocumento}" >  
                        <f:selectItems value="#{managerSearchRealty.tipoDocumentoList()}" />
                        <p:ajax event="change" update=":userForm:ownerPanel" 
                                />
                    </p:selectOneRadio>

                    <div class="clear"/>

                    <p:outputLabel id="typeDocumentLabel" 
                                   value="#{managerSearchRealty.owner.tipoDocumento}: " 
                                   styleClass="grid_3"/>

                    <p:inputMask id="typeDocumentInput" 
                                 value="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CPF' ? 
                                          managerSearchRealty.owner.cpf : managerSearchRealty.owner.cnpj}"
                                 mask="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CPF' ? 
                                         '999.999.999-99':'99.999.999/9999-99'}" 
                                 styleClass="grid_8" > 

                    </p:inputMask>
                    <div class="clear"/>
                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CPF'}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_20 ajustInput" 
                                 value="#{managerSearchRealty.owner.nome}" 
                                 rendered="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                   rendered="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CNPJ'}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_20 ajustInput"
                                 value="#{managerSearchRealty.owner.nomeFantasia}" 
                                 rendered="#{managerSearchRealty.owner.tipoDocumento.tipo eq 'CNPJ'}" />



                </p:panel>

                <p:panel id="addressPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <h4 class="title">Endereço</h4>
                    <p:outputLabel value="CEP:" styleClass="grid_3" for="cepInputMask" />
                    <p:inputMask id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                 value="#{managerSearchRealty.endereco.cep}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Logradouro:" styleClass="grid_3   " for="patioInputText" />
                    <p:inputText id="patioInputText" styleClass="grid_20"
                                 value="#{managerSearchRealty.endereco.logradouro}" />

                    <p:outputLabel value="Bairro:" styleClass="grid_3" for="neighborhoodInputText" />
                    <p:inputText id="neighborhoodInputText" styleClass="grid_20"
                                 value="#{managerSearchRealty.endereco.bairro}" />

                </p:panel>

                <p:panel id="bookPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <h4 class="title">Livro</h4>

                    <p:outputLabel value="Livro:" styleClass="grid_3" for="numberBookInputText" />
                    <p:inputText id="numberBookInputText" styleClass="grid_8"
                                 value="#{managerSearchRealty.realty.book}" />

                    <p:outputLabel value="Folha:" styleClass="grid_4 alpha" for="leafInputText" />
                    <p:inputText id="leafInputText" styleClass="grid_8"
                                 value="#{managerSearchRealty.realty.leaf}" />

                </p:panel>

                <br/>

                <div class="buttonAction">
                    <p:commandButton value="Pesquisar" icon="ui-icon-search"
                                     update="tableReq"
                                     actionListener="#{managerSearchRealty.search()}"
                                     styleClass="ui-priority-primary" />
                    <p:commandButton value="Limpar" icon="ui-icon-close"
                                     actionListener="#{managerSearchRealty.clear()}"
                                     update="@form" />
                </div >

                <p:panel id="resultPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix ">
                    <h4 class="title">Resultado</h4>

                    <p:dataTable id="tableReq" var="item" value="#{managerSearchRealty.imoveis}" 
                                 styleClass="grid_24" rowIndexVar="rowid"
                                 rowKey="#{item.id}" rows="5" paginator="true"  
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro">  
                        <f:facet name="header">
                            Imóvel
                        </f:facet>
                        <p:column headerText="Ação" width="60">
                            <p:button  style="width: 20px; height: 20px;" 
                                       title="Editar"
                                       href="editaraforamento.xhtml?realtyId=#{item.id}"
                                       icon="ui-icon-pencil"/>
                            <p:button  style="width: 20px; height: 20px;" 
                                       title="Visualizar"
                                       href="visualizaraforamento.xhtml?realtyId=#{item.id}"
                                       icon="ui-icon-zoomin"/>

                        </p:column>

                        <p:column headerText="Imóvel" width="150">  
                            <ui:repeat value="#{item.enderecoImovel}" var="i">
                                <h:outputText value="Logradouro #{i.logradouro}, bairro #{i.bairro}, Nº #{i.numero} "/>
                            </ui:repeat>
                        </p:column>
                        <p:column headerText="Proprietário" width="100">  
                            <ui:repeat value="#{item.proprietarios}" var="o">
                                <h:outputText value="#{o.tipoDocumento eq 'CPF' ? o.nome : o.nomeFantasia}"/>
                                <br/>
                            </ui:repeat>
                        </p:column> 

                    </p:dataTable> 

                </p:panel>

                <div class="buttonAction">
                    <p:button value="Voltar" href="indexaforamento.xhtml"
                              icon="ui-icon-arrowreturnthick-1-w"/>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
